package demon1;

import java.util.Arrays;

public class SeqList {
    public int[] elem;
    public int usedNumber;
    public SeqList(int[] elem){
        this.elem=new int[10];
    }
    public boolean isFull(){
        if(this.usedNumber==elem.length){
            return false;
        }
        return true;
    }
    //向顺序表中插入元素,头插
    public void add(int key){
        //首先怕判断顺序表是否满吗,如果满了就要扩容
        if(isFull()){
            this.elem= Arrays.copyOf(this.elem,2*elem.length);
        }
        this.elem[usedNumber]=key;
        usedNumber++;
    }
    //在指定位置插入元素
    public void add(int index,int key){
        //判断index是否合法
        try{
            if(index<0||index> elem.length){
                throw new RuntimeException();
            }
        }catch (RuntimeException e){
            e.printStackTrace();
        }
        if(isFull()){
            this.elem=Arrays.copyOf(this.elem,2*elem.length);
        }


    }

}
